package org.fund.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.fund.base_service.domain.TransactionRecord;
import org.fund.base_service.domain.input.base.PageDomain;
import org.fund.base_service.service.TransactionRecordService;
import org.fund.common.core.domain.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 买卖记录(TransactionRecord)表控制层
 *
 * @author makejava
 * @since 2022-03-13 01:28:44
 */
@RestController
@RequestMapping("/transactionRecord")
@Api(tags = "买卖记录 ")
@SuppressWarnings("unchecked")
public class TransactionRecordController {
    /**
     * 服务对象
     */
    @Autowired
    private TransactionRecordService transactionRecordService;


    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @PostMapping("/list")
    @ApiOperation(value = "查询所有")
    public BaseResult<PageInfo<TransactionRecord>> queryByPage(@RequestBody PageDomain page) {
        return BaseResult.success(transactionRecordService.queryByPage(page));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping
    @ApiOperation(value = "通过主键查询单条数据")
    public BaseResult<TransactionRecord> queryById(@RequestParam("id") Integer id) {
        return BaseResult.success(this.transactionRecordService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param transactionRecord 实体
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation(value = "新增数据")
    public BaseResult<TransactionRecord> add(@RequestBody TransactionRecord transactionRecord) {
        return BaseResult.success(transactionRecordService.insert(transactionRecord));
    }

    @GetMapping("/getlist")
    @ApiOperation(value = "根据持仓查询交易记录")
    public BaseResult<TransactionRecord> add(@RequestParam("id")Integer id) {
        return BaseResult.success(transactionRecordService.queryByPositionId(id));
    }


}

